<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="充值日期">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="会员" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入会员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['refill:refill:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['refill:refill:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['refill:refill:remove']"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['refill:refill:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="refillList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单编号" align="center" prop="id" />
      <el-table-column label="会员" align="center" prop="mid" />
      <el-table-column label="会员姓名" align="center" prop="member2.name" />
<!--      <el-table-column label="会员电话" align="center" prop="member2.phone" />-->
      <el-table-column label="充值金额" align="center" prop="money" />
      <el-table-column label="充值类型" align="center" prop="refilltype.name" />
      <el-table-column label="充值日期" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作员" align="center" prop="sysUser2.name" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['refill:refill:edit']"-->
<!--          >修改</el-button>-->

          <el-button type="primary" @click=" handleViewDetails(scope.row)">详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['refill:refill:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog
      title="详情"
      :visible.sync="open"
      width="90%"
      @close="handleClose"
    >


      <!--      <el-descriptions title="用户信息"  style="width: 100%">-->
      <!--        <el-descriptions-item label="用户名" align="center" prop="this.mydetails.id" />-->
      <!--        <el-descriptions-item label="手机号">{{ mydetails.id }}</el-descriptions-item>-->
      <!--        <el-descriptions-item label="居住地">苏州市</el-descriptions-item>-->
      <!--        <el-descriptions-item label="备注">-->
      <!--          <el-tag size="small">学校</el-tag>-->
      <!--        </el-descriptions-item>-->
      <!--        <el-descriptions-item label="联系地址">江苏省苏州市吴中区吴中大道 1188 号</el-descriptions-item>-->
      <!--      </el-descriptions>-->


      <span>用户信息</span>
      <el-table
        style="width: 100%" :data="mydetails">
        <el-table-column label="会员号" align="center" prop="member2.id" />
        <el-table-column label="会员名称" align="center" prop="member2.name" />
        <el-table-column label="性别" align="center" prop="member2.sex" />
        <el-table-column label="手机号" align="center" prop="member2.phone" />
        <el-table-column label="身份证号" align="center" prop="member2.idcard" />
        <el-table-column label="会员等级" align="center" prop="member2.mrange" />
      </el-table>
      <span>支付信息</span>
      <el-table
        style="width: 100%" :data="mydetails">
        <el-table-column label="订单编号" align="center" prop="id" />
        <el-table-column label="会员名称" align="center" prop="member2.name" />
        <el-table-column label="充值类型" align="center" prop="refilltype.name" />
        <el-table-column label="金额" align="center" prop="money" />
        <el-table-column label="操作人" align="center" prop="sysUser2.name" />
        <el-table-column prop="createTime" label="日期" width="180"></el-table-column>
      </el-table>



      <span slot="footer" class="dialog-footer">
<!--        <el-button @click="cancel" onclick="refreshPage()" >取 消</el-button>-->
              <el-button @click="quxiao"  >取 消</el-button>

      </span>
    </el-dialog>
  </div>
</template>

<script>
import { listRefill, getRefill, delRefill, addRefill, updateRefill } from "@/api/refill/refill";

export default {
  name: "Refill",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 充值记录表格数据
      refillList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 会员时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        rType: null,
        createTime: null,
        mId: null,

      },
      // 表单参数
      form: {},

      mydetails: [],
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //点击刷新
    refreshPage() {
      location.reload(); // 刷新当前页面
    },
    quxiao(){
      this.refreshPage();
      this.handleClose();
    },
    //详情

    /** 查询充值记录列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listRefill(this.queryParams).then(response => {
        this.refillList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        money: null,
        rType: null,
        createTime: null,
        sId: null,
        mId: null,
        del: null,
        name: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加充值记录";
    },
    handleViewDetails(row) {
      this.reset();
      const id = row.id
      getRefill(id).then(response => {
        this.mydetails[0] = response.data;
        console.log("================")
        console.log(this.mydetails)
        this.open = true;
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRefill(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改充值记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRefill(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRefill(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },


    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除充值记录编号为"' + ids + '"的数据项？').then(function() {
        return delRefill(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('refill/refill/export', {
        ...this.queryParams
      }, `refill_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
